package net.wanho.shop.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.wanho.shop.po.Permission;
import net.wanho.shop.service.PermissionService;
import net.wanho.shop.vo.AjaxResult;
import net.wanho.shop.vo.PermVo;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;


/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Api(tags = "05.权限表接口")
@RestController
@RequestMapping("/rights")
@RequiredArgsConstructor
public class PermissionController {

    private final PermissionService permissionService;

//    @ApiOperation("权限表分页查询")
//    @GetMapping("/list")
//    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pagenum, @ApiParam("页大小") @RequestParam(defaultValue = "5") int pagesize, @ApiParam("查询条件") Permission permission) {
//        PageInfo<Permission> pageInfo = permissionService.findPage(pagenum, pagesize, permission);
//        return AjaxResult.success(pageInfo);
//    }

//    @ApiOperation("根据主键查询权限表")
//    @GetMapping("/{psId}")
//    public AjaxResult findById(@PathVariable Serializable psId) {
//        return AjaxResult.success(permissionService.findById(psId));
//    }

    @ApiOperation("新增权限表")
    @PostMapping
    public AjaxResult add(@RequestBody Permission permission) {
        permissionService.add(permission);
        return AjaxResult.success();
    }

    @ApiOperation("修改权限表")
    @PutMapping
    public AjaxResult modify(@RequestBody Permission permission) {
        permissionService.modify(permission);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除权限表")
    @DeleteMapping("/{psId}")
    public AjaxResult removeById(@PathVariable Serializable psId) {
        permissionService.removeById(psId);
        return AjaxResult.success();
    }

    @ApiOperation("所有权限列表")
    @GetMapping("/{type}")
    public AjaxResult findType(@PathVariable String type) {
        List<PermVo> list = permissionService.findType(type);
        return AjaxResult.success(list);
    }
}
